<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateCarRecordsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('car_records', function (Blueprint $table) {
            $table->id();
            $table->string('openid')->comment('微信用户openid');
            $table->date('use_date')->comment('用车日期');
            $table->enum('car_type', ['daily_rent', 'fixed_price'])->comment('用车类型：daily_rent日租，fixed_price一口价');
            $table->string('car_model')->comment('车型');
            $table->string('driver_name')->comment('司机姓名');
            $table->string('license_plate')->comment('车牌号');
            $table->unsignedBigInteger('dispatcher_id')->comment('调车人ID');
            $table->string('passenger_name')->comment('用车人');
            $table->time('start_time')->comment('开始时间');
            $table->time('end_time')->comment('结束时间');
            $table->decimal('mileage', 8, 2)->default(0)->comment('里程数');
            $table->decimal('base_price', 8, 2)->default(0)->comment('基价');
            $table->integer('work_hour_limit')->default(0)->comment('限工作小时');
            $table->decimal('km_limit', 8, 2)->default(0)->comment('限公里数');
            $table->decimal('overtime_fee_per_hour', 8, 2)->default(0)->comment('每小时超时费');
            $table->decimal('over_km_fee', 8, 2)->default(0)->comment('超每公里费');
            $table->decimal('parking_fee', 8, 2)->default(0)->comment('停车费');
            $table->boolean('parking_fee_included')->default(true)->comment('停车费是否实报');
            $table->decimal('toll_fee', 8, 2)->default(0)->comment('路费');
            $table->boolean('toll_fee_included')->default(true)->comment('路费是否实报');
            $table->decimal('accommodation_fee', 8, 2)->default(0)->comment('住宿费');
            $table->boolean('accommodation_fee_included')->default(true)->comment('住宿费是否实报');
            $table->decimal('fuel_fee', 8, 2)->default(0)->comment('油费');
            $table->boolean('fuel_fee_included')->default(true)->comment('油费是否实报');
            $table->decimal('meal_fee', 8, 2)->default(0)->comment('餐费');
            $table->boolean('meal_fee_included')->default(true)->comment('餐费是否实报');
            $table->decimal('car_wash_fee', 8, 2)->default(0)->comment('洗车费');
            $table->boolean('car_wash_fee_included')->default(true)->comment('洗车费是否实报');
            $table->decimal('water_fee', 8, 2)->default(0)->comment('水费');
            $table->boolean('water_fee_included')->default(true)->comment('水费是否实报');
            $table->decimal('other_fee', 8, 2)->default(0)->comment('其他费用');
            $table->boolean('other_fee_included')->default(true)->comment('其他费用是否实报');
            $table->text('route_description')->nullable()->comment('行程描述');
            $table->decimal('total_amount', 10, 2)->default(0)->comment('总金额');
            $table->foreign('dispatcher_id')->references('id')->on('dispatchers');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('car_records');
    }
}
